<template>
	<u-overlay :show="show" :opacity="0.3" :mask-click-able="false">
		<view class="warp">
			<view class="public-container">
				<u-icon name="checkbox-mark" color="#FFFFFF" size="36"></u-icon>
				<text class="message">{{message}}</text>
			</view>
		</view>
	</u-overlay>
</template>

<script setup lang="ts">
	import {ref, onBeforeUnmount} from 'vue'
	
	const show = ref<boolean>(false)
	const message = ref<string>('申请成功')
	const type = ref<string>('sucess')
	const timeId = ref<any>(null)
	
	// 弹窗类型
	interface Options {
	    type: string
	    message: string
		show: boolean
		time?: number
	}
	
	const handleShow = (options: Options) => {
		show.value = options.show
		message.value = options.message
		type.value = options.type
		const time = options.time ? 1500 : options.time
		timeId.value = setTimeout(()=> {
			show.value = false
		}, time)
	}
	
	const clearTimeId = () => {
		clearTimeout(timeId.value)
		timeId.value = null
	}
	onBeforeUnmount(() => {
		clearTimeId()
	})
	defineExpose({
		handleShow
	})
</script>

<style lang="scss" scoped>
.warp {
	display: flex;
	align-items: center;
	justify-content: center;
	height: 100%;
	
	.public-container {
		width: 250rpx;
		height: 250rpx;
		background: #545454;
		border-radius: 20rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		
		.message {
			margin-top: 30rpx;
			font-size: 32rpx;
			color: #FFFFFF;
		}
	}
}
</style>